<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class acount extends CI_Controller
 * @author
 * 用户
 */
class Loans extends CRUD_Controller
{

    function __construct()
    {
        parent::__construct();


        $this->rules = array(
            "rule" => array(
                array(
                    "field" => "timeline",
                    "label" => lang('time'),
                    "rules" => "trim"
                )
            )
        );

    }
    public function _vdata(&$vdata)
    {
        $vdata['title'] = '贷款申请';
    }



    protected function _index_orders(){
        return array('id'=>'desc');
    }
    public function search($page=1){
        $title = "会员中心";
        $vdata['title'] = $title;

        $limit = $this->page_limit;
        $this->input->get('limit',TRUE) and is_numeric($this->input->get('limit')) AND $limit = $this->input->get('limit');
        $order = $this->input->get('order',TRUE) ? $this->input->get('order',TRUE):FALSE;
        $where = array();
        if ($ctype = $this->input->get('ctype',TRUE) AND is_numeric($ctype)) {
            $where['ctype'] = $ctype;
        }


        if($this->input->get('type',TRUE)){
            $status=$this->input->get('type',TRUE);
            if(in_array($status,array(99,1))){
                if($status==99){
                    $status=0;
                }
                $where_q=array('type'=>$status);
                $where = array_merge($where,$where_q);
            }
        }
        if($this->input->get('status',TRUE)){
            $status=$this->input->get('status',TRUE);
            if(in_array($status,array(99,1,2))){
                if($status==99){
                    $status=0;
                }
                $where_q=array('status'=>$status);
                $where = array_merge($where,$where_q);
            }
        }
        $vdata['pages'] = $this->_pages(site_url($this->class.'/search/'),$limit,$where,4);
        $vdata['list'] = $this->model->get_list($limit,$limit*($page-1),$order,$where);
        //print_r($this->db->last_query());
        $vdata['count'] = $this->model->get_count_all($where);
        $this->_display($vdata,$this->class.'_index.php');
    }

    public function audit($key = FALSE){
        if (!$key AND $this->input->post('ids') ) {
            $key = explode(',',$this->input->post('ids'));
        }else{
            $vdata = array('status'=>0,'msg'=>'缺少ID');
        }

        $where = FALSE;

        $audit = $this->input->post('audit');

        if ($audit) {

        }else{
            $audit=0;
        }

        $msg = array('未处理','无意向','有意向');
        if (!isset($vdata['status'])) {
            foreach ($key as $k => $v) {
                $this->db->update('loans', array('status'=>$audit),array('id' => $v));
            }
            //if ($res) {
            $vdata = array('status'=>1,'msg'=>$msg[$audit]);
            if (is_array($key)) {
                $this->mlogs->add('audit',lang('modules_audit_id').$this->input->post('ids').lang('modules_audit_for').$audit);
            }else{
                $this->mlogs->add('audit',lang('modules_audit_id').$key.lang('modules_audit_for').$audit);
            }
        }
        $vdata['audit']=$audit;
        if($this->input->is_ajax_request()){
            $this->output->set_content_type('application/json')->set_output(json_encode($vdata));
        }else{
            $this->load->view('msg',$vdata);
        }
    }
}
